package com.yw.smartcity_study.api;

import android.widget.Toast;

import com.yw.smartcity_study.App;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public abstract class ICallback<T> implements Callback<T> {


    @Override
    public void onResponse(Call<T> call, Response<T> response) {
        if(response.isSuccessful()){
            //响应成功了，应该干什么
            onSuccess(response.body());
        }else{
            Toast.makeText(App.app, response.message(), Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onFailure(Call<T> call, Throwable throwable) {
        Toast.makeText(App.app, "网络错误", Toast.LENGTH_SHORT).show();
    }

    public abstract void onSuccess(T response);

}
